home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / spoc88 / proasm / open.asm < prev    next >
Assembly Source File  |  1988-06-09  |  2KB  |  61 lines

  1.  
  2. COMMENT @*************************************************************
  3.  
  4. This program receives the address of an ASCIIZ string (a string
  5. that ends with a binary zero).  The string contains the name of
  6. a file that is to be opened.  The program opens the file and
  7. returns an integer that acts as a file reference (also called
  8. a file handle).  We return the file handle by placing its
  9. address on the stack.
  10.  
  11.  
  12.    |  10  | <--- FIRST PARM (INPUT PARM)
  13.    |  9   |
  14.    |  8   |
  15.    |  7   |
  16.    |  6   | <--- SECOND PARM (OUTPUT PARM) 32 BIT POINTER
  17.    |  5   |
  18.    |  4   |
  19.    |  3   |
  20.    |  2   |   RETURN ADDRESS
  21.    |  1   |
  22.    |  0   |   BP
  23.    --------
  24.   TOP OF STACK
  25.  
  26. ---------------------------------------------------------------------@
  27.  
  28. A_PROG       SEGMENT BYTE
  29.            ASSUME CS: A_PROG
  30. PUBLIC       open_0
  31. open_0   PROC   FAR
  32.            MOV SI,DS                  ;save SI
  33.            PUSH BP                    ;save BP on stack
  34.            MOV BP,SP                  ;BP = SP
  35.            MOV DX, [BP]+ 10           ;get offset address of filename
  36.            MOV DS, [BP]+ 12           ;get segment addr of   filename
  37.            SUB AL,AL                  ;Set Al to 0 for read access
  38.            MOV AH,3Dh                 ;Specify open function
  39.            INT 21h                    ;Invoke the interrupt
  40.  
  41.            JC  FAILURE
  42.            LDS DI,DWORD PTR [BP] + 6  ;make DI point to output parm 
  43. ;;;;;;;;;        SUB AH,AH                  ;
  44.  
  45.            MOV [DI],AX                ;Move AX to FileHANDLE
  46.            POP BP                     ;Restore BP
  47.            MOV DS,SI                  ;Restore DS
  48.            RET 8                      ;pop the parms off the stack
  49. FAILURE:
  50.            MOV AX,0FFh                ;0FFh will be error flag
  51.            LDS DI,DWORD PTR [BP] + 6  ;Make DI point to output parm 
  52.            MOV [DI],AX                ;Move error value to FileHANDLE
  53.            POP BP                     ;Restore BP
  54.            MOV DS,SI                  ;Restore DS
  55.            RET 8                      ;pop the parms off the stack
  56.  
  57. open_0   ENDP
  58. A_PROG     ENDS
  59. END
  60.                  
  61.